package com.fire.market.server.impl;

import com.fire.component.dto.Response;
import com.fire.component.dto.SingleResponse;

import com.fire.market.product.api.dto.ItemInfo;
import com.fire.market.product.api.mq.ItemStockMqMessage;
import com.fire.market.product.api.request.ItemAddParam;
import com.fire.market.product.api.request.ItemDecreaseParam;
import com.fire.market.product.api.result.ItemStockDecreaseResult;
import com.fire.market.product.api.service.ItemCmdFrontService;
import com.fire.market.service.impl.ItemCmdCoreService;
import org.apache.dubbo.config.annotation.Service;

import javax.annotation.Resource;

/**
 * ItemCmdFrontServiceImpl
 *
 * @author zwd
 * @date 2021/7/20
 */
@Service
public class ItemCmdFrontServiceImpl implements ItemCmdFrontService {
    @Resource
    ItemCmdCoreService itemCmdCoreService;
    @Override
    public SingleResponse<ItemInfo> addItem(ItemAddParam param) {
        return SingleResponse.of(itemCmdCoreService.createItem(param));
    }

    @Override
    public SingleResponse<ItemStockDecreaseResult> decreaseItemStockByCache(ItemDecreaseParam param) {
        return SingleResponse.of(itemCmdCoreService.decreaseItemStockByCache(param));
    }

    @Override
    public Response increaseSales(Integer itemId, Integer amount) {
        itemCmdCoreService.increaseSales(itemId, amount);
        return Response.buildSuccess();
    }

    @Override
    public Response decreaseSales(ItemDecreaseParam itemDecreaseParam) {
        itemCmdCoreService.decreaseSales(itemDecreaseParam.getItemId(), itemDecreaseParam.getAmount());
        return Response.buildSuccess();
    }

    @Override
    public Response syncDecreaseItemStockByMq(ItemStockMqMessage itemStockMqMessage) {
        itemCmdCoreService.syncDecreaseItemStockByMq(itemStockMqMessage);
        return Response.buildSuccess();
    }

    @Override
    public Response increaseItemStockByCache(ItemDecreaseParam param) {
        itemCmdCoreService.increaseItemStockByCache(param);
        return Response.buildSuccess();
    }
}
